﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Sale
{
    public partial class HeTong_FuLiao_GongYePin_MaiMai_SheZhi : System.Web.UI.Page
    {
        protected string 供货单位ID;
        protected string 供货商;
        protected void Page_Load(object sender, EventArgs e)
        {
            int BillID = 0;
            if (!this.IsPostBack)
            {
                this.Year0.SelectedValue = DateTime.Today.Year.ToString();
                this.Month0.SelectedValue = DateTime.Today.Month.ToString();
                this.Year.SelectedValue = DateTime.Today.Year.ToString();
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out BillID);
                }
                if (BillID > 0)
                {
                    SqlConnection Conn = new SqlConnection();
                    Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                    Conn.Open();
                    SqlCommand Cmd = new SqlCommand();
                    Cmd.Connection = Conn;
                    Cmd.CommandText = @"Select 
                     [辅料采购合同].[辅料ID],
                     [辅料采购合同].[合同编号], 
                     [辅料采购合同].[供货单位ID],
                     [材料].[品名],
                     [材料].规格,
                     [材料].单位,
                     [辅料采购合同].签订日期,
                      数量,
                     [辅料采购合同].单价,
                     金额,
                     长度,                    
                     交货时间,
                     交货数量,
                     [辅料采购合同].[数量] as [采购量], 
                     [辅料采购合同].[签订日期],[年度],[月份]
                     from [辅料采购合同],[辅料供货单位],[材料]
                     where [辅料供货单位].[ID]= [辅料采购合同].[供货单位ID]
                     and [材料].[ID]= [辅料采购合同].[辅料ID] and 辅料采购合同.ID=" + BillID+" and [辅料采购合同].[合同编号]=(select 合同编号 from 辅料采购合同 where 辅料采购合同.ID=" + BillID + ")";
                    Cmd.CommandType = CommandType.Text;
                    SqlDataReader Reader = Cmd.ExecuteReader();
                    for (int i = 1; i <= 1; i++)
                    {
                        if (!Reader.Read())
                        {
                            break;
                        }
                        this.ViewState["BillID"] = BillID;
                        //this.GongHuoFang.SelectedItem.Text = Reader.GetString(2);
                        this.HeTongHao.Text = Reader.GetString(1);
                        this.GongHuoFang.Text = Reader.GetInt32(2).ToString();
                        this.RiQi.Text = Reader.GetDateTime(6).ToString("d");

                        this.ViewState["id" + i] = Reader.GetInt32(0).ToString();
                        if (Reader.IsDBNull(3))
                        {
                            ((TextBox)this.FindControl("R" + i + "_C1")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C1")).Text = Reader.GetString(3);
                        }
                        ((TextBox)this.FindControl("R" + i + "_C3")).ReadOnly = false;
                        ((TextBox)this.FindControl("R" + i + "_C3")).CssClass = "intxt1";
                        if (Reader.IsDBNull(4))
                        {
                            ((TextBox)this.FindControl("R" + i + "_C2")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C2")).Text = Reader.GetString(4);
                        }
                        ((TextBox)this.FindControl("R" + i + "_C4")).Text = Reader.GetString(5);
                        if (Reader.IsDBNull(7))
                        {
                            ((TextBox)this.FindControl("R" + i + "_C3")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C3")).Text = Reader.GetSqlSingle(7).ToString();
                        }
                        if (Reader.IsDBNull(8))
                        {
                            ((TextBox)this.FindControl("R" + i + "_C5")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C5")).Text = Reader.GetSqlMoney(8).ToString();
                        }
                        ((TextBox)this.FindControl("R" + i + "_C5")).ReadOnly = false;
                        ((TextBox)this.FindControl("R" + i + "_C5")).CssClass = "intxt1";
                        //if (Reader.IsDBNull(9))
                        //{
                        //    ((TextBox)this.FindControl("R" + i + "_C6")).Text = "";
                        //}
                        //else
                        //{
                        //    ((TextBox)this.FindControl("R" + i + "_C6")).Text = Reader.GetSqlMoney(9).ToString();
                        //}
                        if (Reader.IsDBNull(10))
                        {                            
                            ((TextBox)this.FindControl("R" + i + "_C7")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C7")).Text = Reader.GetDecimal(10).ToString();
                        }
                        ((TextBox)this.FindControl("R" + i + "_C7")).ReadOnly = false;
                        ((TextBox)this.FindControl("R" + i + "_C7")).CssClass = "intxt1";


                        ((TextBox)this.FindControl("R" + i + "_C9")).Text = Reader.GetString(11).ToString();
                        ((TextBox)this.FindControl("R" + i + "_C9")).CssClass = "intxt1";
                        ((TextBox)this.FindControl("R" + i + "_C9")).Enabled = true;
                        ((TextBox)this.FindControl("R" + i + "_C9")).ReadOnly = false;
                        //((DropDownList)this.FindControl("DropDownList" + i)).Visible = true;
                        //((DropDownList)this.FindControl("DropDownList" + i)).SelectedValue = Reader.GetString(11).ToString();
                        if (Reader.IsDBNull(10))
                        {
                            ((TextBox)this.FindControl("R" + i + "_C8")).Text = "";
                        }
                        else
                        {
                            ((TextBox)this.FindControl("R" + i + "_C8")).Text = Reader.GetDouble(12).ToString();
                        }
                        ((TextBox)this.FindControl("R" + i + "_C8")).ReadOnly = false;
                        ((TextBox)this.FindControl("R" + i + "_C8")).CssClass = "intxt1";
                        this.Year0.SelectedValue = Reader.GetInt32(15).ToString();
                        this.Month0.SelectedValue = Reader.GetInt32(16).ToString();
                        ((Button)this.FindControl("Button_Add" + i)).Text = "删 除";
                        this.Year0.SelectedValue = Reader.GetInt32(15).ToString();
                    

                    }
                    Reader.Close();
                    Conn.Close();
                    Reader.Dispose();
                    Cmd.Dispose();
                    Conn.Dispose();

                }
            }
        }
        protected void Button_Add_Command(object sender, CommandEventArgs e)
        {
            int row;
            int.TryParse(e.CommandArgument.ToString(), out row);
            this.ViewState["row"] = row;

            if (this.ViewState["id" + row] == null)
            {
                string sql = "select 年度,季度,供货单位ID,材料.ID,品名,名称,规格,单位,辅料中标书.数量,辅料中标书.单价,日期 from 材料 inner join 辅料中标书 on 辅料中标书.辅料ID=材料.ID inner join 辅料供货单位 on 辅料供货单位.ID=辅料中标书.供货单位ID";
                this.SqlDataSource3.SelectCommand = sql;
                this.GridView1.DataSource = SqlDataSource3;
                this.GridView1.DataBind();
                this.Panel_Grid.Visible = true;
                this.Message.Text = "·准备添加";
            }
            else
            {
                this.ViewState["id" + row] = null;
                ((TextBox)this.FindControl("R" + row + "_C1")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C2")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C3")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C3")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C3")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C4")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C4")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C4")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C5")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C5")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C5")).Text = "";
                //((TextBox)this.FindControl("R" + row + "_C6")).ReadOnly = true;
                //((TextBox)this.FindControl("R" + row + "_C6")).CssClass = "blank_center";
                //((TextBox)this.FindControl("R" + row + "_C6")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C7")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C7")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C7")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C8")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C8")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C8")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C9")).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + row + "_C9")).Text = "";
                ((TextBox)this.FindControl("R" + row + "_C9")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + row + "_C9")).Enabled = false;
                //((DropDownList)this.FindControl("DropDownList" + row)).Visible = false;
                ((Button)this.FindControl("Button_Add" + row)).Text = "添 加";
                this.Message.Text = "·删除成功";
            }
        }

        protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
        {
            this.Panel_Grid.Visible = false;
            this.Message.Text = "·已取消添加";
        }
        protected void Button1_Command(object sender, CommandEventArgs e)
        {

            int row = (int)this.ViewState["row"];
            string[] Args = e.CommandArgument.ToString().Split("\t".ToCharArray());

            this.ViewState["id" + row] = Args[0];
            供货单位ID = Args[8];
            供货商 = Args[9];
            this.GongHuoFang.SelectedValue = 供货单位ID;
            this.GongHuoFang.Enabled = false;
            ((TextBox)this.FindControl("R" + row + "_C1")).Text = Args[1];
            ((TextBox)this.FindControl("R" + row + "_C2")).Text = Args[3];
            ((TextBox)this.FindControl("R" + row + "_C3")).Text = Args[5];
            ((TextBox)this.FindControl("R" + row + "_C3")).ReadOnly = false;
            ((TextBox)this.FindControl("R" + row + "_C3")).CssClass = "intxt1";
            ((TextBox)this.FindControl("R" + row + "_C4")).Text = Args[2];
            double money = double.Parse(Args[4]);
            ((TextBox)this.FindControl("R" + row + "_C5")).Text = money.ToString("0.00");
            ((TextBox)this.FindControl("R" + row + "_C5")).ReadOnly = false;
            ((TextBox)this.FindControl("R" + row + "_C5")).CssClass = "intxt1";
            //((TextBox)this.FindControl("R" + row + "_C6")).Text = "";
            //((TextBox)this.FindControl("R" + row + "_C6")).ReadOnly = false;
            //((TextBox)this.FindControl("R" + row + "_C6")).CssClass = "intxt1";
            ((TextBox)this.FindControl("R" + row + "_C7")).Text = "";
            ((TextBox)this.FindControl("R" + row + "_C7")).ReadOnly = false;
            ((TextBox)this.FindControl("R" + row + "_C7")).CssClass = "intxt1";
            ((TextBox)this.FindControl("R" + row + "_C8")).Text = "";
            ((TextBox)this.FindControl("R" + row + "_C8")).ReadOnly = false;
            ((TextBox)this.FindControl("R" + row + "_C8")).CssClass = "intxt1";
            ((TextBox)this.FindControl("R" + row + "_C9")).Enabled = true;
            ((TextBox)this.FindControl("R" + row + "_C9")).Text = "";
            ((TextBox)this.FindControl("R" + row + "_C9")).ReadOnly = false;
            ((TextBox)this.FindControl("R" + row + "_C9")).CssClass = "intxt1";
            //((DropDownList)this.FindControl("DropDownList" + row)).Visible = true;
            ((Button)this.FindControl("Button_Add" + row)).Text = "删 除";
            this.Panel_Grid.Visible = false;
            this.Message.Text = "·添加成功";
        }
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            this.TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
            this.Label_Pages.Text = " 共" + this.GridView1.PageCount.ToString() + "页 ";

            this.Button_Pager_First.CssClass = "pageturn-first-b";
            this.Button_Pager_First.Enabled = true;
            this.Button_Pager_Prev.CssClass = "pageturn-prev-b";
            this.Button_Pager_Prev.Enabled = true;
            this.Button_Pager_Next.CssClass = "pageturn-next-b";
            this.Button_Pager_Next.Enabled = true;
            this.Button_Pager_Last.CssClass = "pageturn-last-b";
            this.Button_Pager_Last.Enabled = true;
            if (this.GridView1.PageIndex == 0)
            {
                this.Button_Pager_Prev.CssClass = "pageturn-prev-g";
                this.Button_Pager_Prev.Enabled = false;
            }
            if (this.GridView1.PageIndex < 2)
            {
                this.Button_Pager_First.CssClass = "pageturn-first-g";
                this.Button_Pager_First.Enabled = false;
            }
            if (this.GridView1.PageIndex == this.GridView1.PageCount - 1 || this.GridView1.PageCount == 0)
            {
                this.Button_Pager_Next.CssClass = "pageturn-next-g";
                this.Button_Pager_Next.Enabled = false;

            }
            if (this.GridView1.PageIndex > this.GridView1.PageCount - 3)
            {
                this.Button_Pager_Last.CssClass = "pageturn-last-g";
                this.Button_Pager_Last.Enabled = false;
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            this.GridView1_DataBound(null, null);
        }

        protected void Pager_Click(object sender, EventArgs e)
        {
            if (sender.GetType().ToString() == "System.Web.UI.WebControls.Button")
            {
                switch (((Button)sender).CommandName)
                {
                    case "--":
                        this.GridView1.PageIndex = 0;
                        break;
                    case "-":
                        if (this.GridView1.PageIndex > 0) this.GridView1.PageIndex--;
                        break;
                    case "+":
                        if (this.GridView1.PageIndex < this.GridView1.PageCount - 1) this.GridView1.PageIndex++;
                        break;
                    case "++":
                        this.GridView1.PageIndex = this.GridView1.PageCount - 1;
                        break;
                }
            }
            else
            {

                int p;
                if (int.TryParse(TextBox_Pager.Text, out p))
                {
                    if (p >= 1 && p <= this.GridView1.PageCount)
                    {
                        this.GridView1.PageIndex = p - 1;
                    }
                }
                TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
            }
        }

        protected void Button_Finish_Click(object sender, EventArgs e)
        {
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlTransaction Tran = Conn.BeginTransaction();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.Transaction = Tran;
            try
            {
                Cmd.CommandText = "FuLiao_CaiGou_HeTong_MaiMai_In";
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Clear();
                if (this.ViewState["BillID"] == null)
                {
                    this.ViewState["BillID"] = -1;
                }
                Cmd.Parameters.Add(new SqlParameter("@年度", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.Year0.SelectedValue)));
                Cmd.Parameters.Add(new SqlParameter("@月份", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, int.Parse(this.Month0.SelectedValue)));
                if (this.Month0.SelectedValue == "1" || this.Month0.SelectedValue == "2" || this.Month0.SelectedValue == "3")
                {
                    Cmd.Parameters.Add(new SqlParameter("@季度", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 1));
                }
                if (this.Month0.SelectedValue == "4" || this.Month0.SelectedValue == "5" || this.Month0.SelectedValue == "6")
                {
                    Cmd.Parameters.Add(new SqlParameter("@季度", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 2));
                }
                if (this.Month0.SelectedValue == "7" || this.Month0.SelectedValue == "8" || this.Month0.SelectedValue == "9")
                {
                    Cmd.Parameters.Add(new SqlParameter("@季度", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 3));
                }
                if (this.Month0.SelectedValue == "10" || this.Month0.SelectedValue == "11" || this.Month0.SelectedValue == "12")
                {
                    Cmd.Parameters.Add(new SqlParameter("@季度", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 4));
                }
                Cmd.Parameters.Add(new SqlParameter("@供货商ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                Cmd.Parameters.Add(new SqlParameter("@合同编号", SqlDbType.NVarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@签订日期", SqlDbType.Date, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@辅料ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                Cmd.Parameters.Add(new SqlParameter("@数量", SqlDbType.Real, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@单价", SqlDbType.Money, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@金额", SqlDbType.Money, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                Cmd.Parameters.Add(new SqlParameter("@长度", SqlDbType.Decimal, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, 0));
                Cmd.Parameters.Add(new SqlParameter("@交货时间", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@交货数量", SqlDbType.Float, 150, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, null));
                Cmd.Parameters.Add(new SqlParameter("@BillID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.ViewState["BillID"]));
                Cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Proposed, null));

                for (int i = 1; i <= 1; i++)
                {
                    if ((string)ViewState["id" + i] != null)
                    {
                        Cmd.Parameters["@供货商ID"].Value = int.Parse(this.GongHuoFang.SelectedValue);
                        Cmd.Parameters["@合同编号"].Value = this.HeTongHao.Text;
                        Cmd.Parameters["@签订日期"].Value = DateTime.Parse(this.RiQi.Text);

                        Cmd.Parameters["@辅料ID"].Value = int.Parse((string)ViewState["id" + i]);
                        string 数量=((TextBox)this.FindControl("R" + i + "_C3")).Text;
                        if (数量 == "")
                        {
                            this.Message.Text=".数量不能为空!";
                            return;
                        }else{
                        Cmd.Parameters["@数量"].Value = int.Parse(((TextBox)this.FindControl("R" + i + "_C3")).Text);
                        }
                        Cmd.Parameters["@单价"].Value = Decimal.Parse(((TextBox)this.FindControl("R" + i + "_C5")).Text);
                        Cmd.Parameters["@金额"].Value = int.Parse(((TextBox)this.FindControl("R" + i + "_C3")).Text) * (Decimal.Parse(((TextBox)this.FindControl("R" + i + "_C5")).Text));
                        string 长度 = ((TextBox)this.FindControl("R" + i + "_C7")).Text;
                        if (长度 == "")
                        {
                            this.Message.Text = ".长度不能为空!";
                            return;
                        }
                        else
                        {
                            Cmd.Parameters["@长度"].Value = decimal.Parse(((TextBox)this.FindControl("R" + i + "_C7")).Text);
                        }
                        Cmd.Parameters["@交货时间"].Value = ((TextBox)this.FindControl("R" + i + "_C9")).Text;
                        string 交货数量 = ((TextBox)this.FindControl("R" + i + "_C8")).Text;
                        if (交货数量 =="")
                        {
                            this.Message.Text = ".交货数量不能为空!";
                            return;
                        }
                        else
                        {
                            Cmd.Parameters["@交货数量"].Value = ((TextBox)this.FindControl("R" + i + "_C8")).Text;
                        }
                        this.ViewState["BillID"] = (int)Cmd.Parameters["@供货商ID"].Value;
                        int BillID = (int)this.ViewState["BillID"];
                        Cmd.ExecuteNonQuery();
                    }
                }
                this.Message.Text = "·保存成功";
                ((TextBox)this.FindControl("R" + 1 + "_C3")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1 + "_C3")).CssClass = "blank_center";

                ((TextBox)this.FindControl("R" + 1 + "_C5")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1 + "_C5")).CssClass = "blank_center";

                ((TextBox)this.FindControl("R" + 1 + "_C7")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1 + "_C7")).CssClass = "blank_center";

                ((TextBox)this.FindControl("R" + 1 + "_C8")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1 + "_C8")).CssClass = "blank_center";

                ((TextBox)this.FindControl("R" + 1 + "_C9")).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1 + "_C9")).CssClass = "blank_center";
                Tran.Commit();
            }
            catch (Exception err)
            {
                Tran.Rollback();
                this.Message.Text = err.Message;
            }
            Cmd.Dispose();
            Tran.Dispose();
            Conn.Close();
            Conn.Dispose();
            //Response.Redirect("HeTong_FuLiao_Search.aspx");
        }

        protected void ToWord_Click(object sender, EventArgs e)
        {

        }
        protected void Select_Click(object sender, EventArgs e)
        {
            string sql = "select 年度,季度,供货单位ID,材料.ID,品名,名称,规格,单位,辅料中标书.数量,辅料中标书.单价,日期 from 材料 inner join 辅料中标书 on 辅料中标书.辅料ID=材料.ID inner join 辅料供货单位 on 辅料供货单位.ID=辅料中标书.供货单位ID where YEAR(日期)='@年份' and month(日期) between '@起始月份' and '@截止月份' and 辅料ID like @辅料ID";
         
                 if (this.JiDu.SelectedValue == "1")
            {
                sql = sql.Replace("@年份", this.Year.SelectedValue);
                sql = sql.Replace("@起始月份", "1");
                sql = sql.Replace("@截止月份", "3");
                if (this.FuLiao.SelectedValue == "0")
                {
                    sql = sql.Replace("@辅料ID", "'%%'");
                }
                else
                {
                    sql = sql.Replace("@辅料ID", this.FuLiao.SelectedValue);
                }
            }
            if (this.JiDu.SelectedValue == "2")
            {
                sql = sql.Replace("@年份", this.Year.SelectedValue);
                sql = sql.Replace("@起始月份", "4");
                sql = sql.Replace("@截止月份", "6");
                if (this.FuLiao.SelectedValue == "0")
                {
                    sql = sql.Replace("@辅料ID", "'%%'");
                }
                else
                {
                    sql = sql.Replace("@辅料ID", this.FuLiao.SelectedValue);
                }
            }
            if (this.JiDu.SelectedValue == "3")
            {
                sql = sql.Replace("@年份", this.Year.SelectedValue);
                sql = sql.Replace("@起始月份", "7");
                sql = sql.Replace("@截止月份", "9");
                if (this.FuLiao.SelectedValue == "0")
                {
                    sql = sql.Replace("@辅料ID", "'%%'");
                }
                else
                {
                    sql = sql.Replace("@辅料ID", this.FuLiao.SelectedValue);
                }
            }
            if (this.JiDu.SelectedValue == "4")
            {
                sql = sql.Replace("@年份", this.Year.SelectedValue);
                sql = sql.Replace("@起始月份", "10");
                sql = sql.Replace("@截止月份", "12");
                if (this.FuLiao.SelectedValue == "0")
                {
                    sql = sql.Replace("@辅料ID", "'%%'");
                }
                else
                {
                    sql = sql.Replace("@辅料ID", this.FuLiao.SelectedValue);
                }
            }
            this.SqlDataSource3.SelectCommand = sql;
            this.GridView1.DataSource = SqlDataSource3;
            this.GridView1.DataBind();
        }               
           
    }
}
